BINPATH  := ./bin/
HEADPATH := ./include/
OBJPATH  := ./obj/
SRCPATH  := ./src/

TAR := $(BINPATH)main
SRC := $(wildcard $(SRCPATH)*.c)
# SRC = ./src/bt.c ./src/main.c
OBJ := $(patsubst $(SRCPATH)%.c, $(OBJPATH)%.o, $(SRC)) 
# OBJ = ./obj/bt.o ./obj/main.o
INC := $(wildcard $(HEADPATH)*.h)
# INC = ./include/bt.h

CFLAGS += -c -g -Wall

.PHONY: compile
compile: clean mkdir $(TAR)

$(TAR): $(OBJ)
	gcc -o $@ $^ 

$(OBJPATH)%.o: $(SRCPATH)%.c $(INC)
	gcc $(CFLAGS) -o $@ $< -I $(HEADPATH)

.PHONY: mkdir
mkdir:
	$@ $(BINPATH) $(OBJPATH)

.PHONY: run
run:
	$(TAR)

.PHONY: debug
debug:
	gdb $(TAR)

.PHONY: clean
clean:
	$(RM) -r $(TAR) .gdb_history $(OBJPATH) $(BINPATH)